/**
 * 
 */
package linux;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author sz
 * 
 *         create time：2013-5-10
 */
public class ProssTest {
	private Runtime runtime = Runtime.getRuntime();// 得到jvm的运行环境
	private Process process;

	public static void main(String[] args) {
		new ProssTest().to_process();
	}

	public void to_process() {
		try {
			//process = runtime.exec("cmd.exe /c dir");// 开启新进程执行命令
			process = runtime.exec(new String[]{"cmd.exe","/c","dir"});// 开启新进程执行命令
			try {
				process.waitFor();// 当前进程等待新开启的进程执行完毕
				if (process.exitValue() != 0) {
					System.out.println("Cmd execute failed pleache check the system!");
				} else {
					// 获取并打印结果
					InputStreamReader isr = new InputStreamReader(process.getInputStream(),"gb2312");
				
					BufferedReader br = new BufferedReader(isr);
					
					String line = null;
					while ((line = br.readLine()) != null) {
						System.out.println(line);
					}
				}
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
